package com.oocl.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.oocl.dao.OrderCommentDao;
import com.oocl.dao.base.BaseJPADaoUtil;
import com.oocl.entity.OrderComment;


@Repository("orderCommentDao")
public class OrderCommentDaoImpl extends BaseJPADaoUtil implements OrderCommentDao{


	
	/*
     * @Method  findByCid
     * @function load OrderComments by   cid
     * @param  cid Clients id 
     * @return list OrderComment List
     * @author garen
     * @date 2017-8-12
     * */
	public List<OrderComment> findByCid(String cid) {
		String sql = "select oc from OrderComment oc where oc.cid=:cid ";
		List<OrderComment> list =  entityManager.createQuery(sql)
		                       .setParameter("cid", cid)
		                       .getResultList();
		return list;
	}

	/*
     * @Method  findByOid
     * @function load OrderComments by oid
     * @param  String oid OrderId
     * @return list OrderComment List
     * @author wendy
     * @date 2017-8-13
     * */
	@Override
	public OrderComment findByOid(String oid) {
		// TODO Auto-generated method stub
		String jpql="select oc from OrderComment oc where oc.oid=:oid";
		List<OrderComment> oclist=entityManager.createQuery(jpql)
						.setParameter("oid", oid)
						.getResultList();
		OrderComment oc=new OrderComment();
		if(oclist.size()>0){
			oc=oclist.get(0);
			return oc;
			
		}
		return null;
	}

	
	@Override
	public List<OrderComment> findCommentListByIcnum(String icnum) {
		String sql = "select oc from OrderComment oc left join fetch oc.merchant ocm where ocm.icnum=:icnum";
		List<OrderComment> ocList = entityManager.createQuery(sql)
				.setParameter("icnum", icnum)
				.getResultList();
		return ocList;
	}


}
